#coding:utf-8
import base64

from django.db import models


class AesCharField(models.CharField):
    """
    model Fields for storing text in a compressed format (bz2 by default)
    """
    ### 获取数据库字段信息并处理
    def from_db_value(self, value, expression, connection, context):
        return base64.b64decode(value).decode()
    ###入库前处理
    def get_prep_value(self, value):
        return base64.b64encode(value.encode())